#ifndef MYTCPSERVER_H
#define MYTCPSERVER_H
#include <QTcpServer>
#include <QVector>
#include "Core/tcpuserconnect.h"
#include <QMutex>
#include "dbcontroler.h"
#include <unordered_set>
#include "Global/singleton.h"
class MyTcpServer :public QTcpServer,public Singleton<MyTcpServer>
{
    Q_OBJECT
public:

    void incomingConnection(qintptr socketDescriptor);

    void Match_UserTcp(TcpUserConnect *Tcp,QString UserName);

    void Delete_UserTcp(TcpUserConnect *Tcp,QString UserName);

    static void distroy_instance();

    TcpUserConnect* FromUserNameGetTcpSocket(QString UserName);

    QString FromTcpSocketGetUserName(TcpUserConnect* UserTcp);

private:
    friend class Singleton<MyTcpServer>;

    MyTcpServer();

    std::unordered_set<TcpUserConnect*>ConnectInfo;


    QMap<QString,QSet<TcpUserConnect*>>UserToTcpList;

    QMap<TcpUserConnect*,QString>TcpToUserName;


    QMap<TcpUserConnect*,QThread*>TcpToThread;

    QMap<QThread*,TcpUserConnect*>ThreadToTcp;

public slots:
    void ExecuteDownLoad(TcpUserConnect* UsrTcp,QString UsrName);

    void ConnectUserAndTcp(TcpUserConnect* UsrTcp,QString UsrName);

};

#endif // MYTCPSERVER_H
